﻿@using System.Linq

<h1>
@ViewBag.IntRef
</h1>

@using (Html.BeginForm("RefreshFetchLeadBlock", "Client"))
{
    @Html.ValidationSummary(true)
    <fieldset>
    <input type="hidden" name="LeadClient" value="@(ViewBag.LeadID)" />
    <table>
    <tr>
    <th>Ref</th>
    <th>Surname</th>
    <th>Telephone</th>
    <th>Postcode</th>
    <th>By Days</th>
    <th>Status</th>
    @if (ViewBag.personcat != "N" && ViewBag.RegionLockDown != true)
    {
    <th>Region</th>    
    }
    <th>&nbsp;</th>
    </tr>
    <tr>
    <td>
    <input type="text" name="leadref" id="filterLeadref" value="@(ViewBag.leadref)" style="width: 60px;"/>/
    @Html.DropDownList("Agent", null, "Select Team")/
    <select name="classification" id="classification">
    <option value="">Select Classification</option>
    <option value="U_New" @(ViewBag.classification == "U_New" ? "selected" : "")>PU - New</option>
    <option value="U_Research" @(ViewBag.classification == "U_Research" ? "selected" : "")>PU - Researched</option>
    <option value="U_Past" @(ViewBag.classification == "U_Past" ? "selected" : "")>PU - Past, Issued</option>
    <option value="U_Face" @(ViewBag.classification == "U_Face" ? "selected" : "")>PU - Face to Face</option>
    <option value="NU_New" @(ViewBag.classification == "NU_New" ? "selected" : "")>NU - New</option>
    <option value="NU_Research" @(ViewBag.classification == "NU_Research" ? "selected" : "")>NU - Researched</option>
    <option value="NU_Past" @(ViewBag.classification == "NU_Past" ? "selected" : "")>NU - Past, Issued</option>
    <option value="NU_Face" @(ViewBag.classification == "NU_Face" ? "selected" : "")>NU - Face to Face</option>
    </select>
    </td>
    <td><input type="text" name="surname" id="filterSurname" value="@(ViewBag.surname)" style="width: 100px;"/></td>
    <td><input type="text" name="telephone" id="filterTelephone"  value="@(ViewBag.telephone)" style="width: 100px;"/></td>
    <td><input type="text" name="postcode" id="filterPostcode"  value="@(ViewBag.postcode)" style="width: 100px;"/></td>
    <td>
    <label>1</label><input type="radio" name="dayfilter" value="1" @(ViewBag.dayFilter == "1" ? "checked" : " ")/>
    <label>7</label><input type="radio" name="dayfilter" value="7" @(ViewBag.dayFilter == "7" ? "checked" : " ")/>
    <label>All</label><input type="radio" name="dayfilter" value="all" @(ViewBag.dayFilter == "all" || ViewBag.dayFilter == "" ? "checked" : " ")/>
    </td>
    <td>
    <select name="leadFilter">
        <option value="">Select a Status</option>
        <option value="Active" @(ViewBag.leadfilter == "Active" ? "selected" : " ")>Active</option>
        <option value="Dead" @(ViewBag.leadfilter == "Dead" ? "selected" : " ")>Dead</option>
        <option value="All" @(ViewBag.leadfilter == "All" ? "selected" : " ")>All</option>
    </select>
    </td>
    @if (ViewBag.personcat != "N")
    {
        <td>
    @if (ViewBag.RegionLockDown == true)
    {
        <input type="hidden" id="regionid" name="regionid" value="@(ViewBag.regionid)" />
    }
    else
    {
        @:@Html.DropDownList("regionid", null, "Select a Region")
    }
        </td>
    }
    <td><input type="submit" value="Search" id="btnFilter" /></td>
    </tr>
    </table>
    @if (ViewBag.personcat == "N")
    {
        @Html.Hidden("regionid", "0")
    }
</fieldset>
}


<div id="showleads">
</div>
	
<script type="text/javascript">

    $(document).ready(function () {
    
    @{
        var testVars = new string[] { ViewBag.surname, ViewBag.telephone, ViewBag.postcode, ViewBag.dayFilter, ViewBag.leadref }
            .FirstOrDefault(s => !string.IsNullOrEmpty(s)) ?? "";

        if (testVars != "")
        {
        <text>
            $("#showleads").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Large quantities of leads may take a little while to appear.</div></div>');
            var link = '?id=@(ViewBag.LeadID)&surname=@(ViewBag.surname)&telephone=@(ViewBag.telephone)&postcode=@(ViewBag.postcode)&dayfilter=@(ViewBag.dayFilter)&leadref=@(ViewBag.leadref)&leadFilter=@(ViewBag.leadfilter)&page=@(ViewBag.page)&agent=@(ViewBag.selectedagent)&regionid=@(ViewBag.selectedregion)&classification=@(ViewBag.classification)';
            $("#showleads").load('@(Url.Action("ShowLeadsByDate", "Client"))' + link);
        </text>
        }
    }

    });
</script>